Exporting to CSV: Preserving "\n" and commas

Hi All,

I am exporting to csv via a buffer and I would like to know if there is a way to preserve the "\n" character so that I may have a column with multiple values. Is there an easy way to do this without a large amount of additional coding? Any help would be greatly appretiated!

Thanks

Matteous
MatteuosR - Fri Jul 01 11:25:09 EDT 2011

Re: Exporting to CSV: Preserving "\n" and commas
David_G_Bond - Fri Jul 01 14:22:50 EDT 2011

I believe that if you surround the entire cell contents with double quotes (") that everything within the quotes will appear in one cell.

  • David Bond

Re: Exporting to CSV: Preserving "\n" and commas
MatteuosR - Fri Jul 01 15:33:57 EDT 2011

I have seen that fix on other sites and i have tried every combination I can think of but the comma and newline characters still act as they would normally. I am using an array to populate a string with attributes that are multi-valued. So there is a dynamic aspect as well.

Regards Matteous

Re: Exporting to CSV: Preserving "\n" and commas
MatteuosR - Fri Jul 01 15:36:46 EDT 2011

Here is the snippet I am trying to work with:
for (i = 0; i < size;i++)
{
ReturnVal = ReturnVal(string get(arr,i,type))"|" - I need "|" to be "\n"
}

return ReturnVal

Re: Exporting to CSV: Preserving "\n" and commas
Mathias Mamsch - Fri Jul 01 16:01:36 EDT 2011

MatteuosR - Fri Jul 01 15:36:46 EDT 2011
Here is the snippet I am trying to work with:
for (i = 0; i < size;i++)
{
ReturnVal = ReturnVal(string get(arr,i,type))"|" - I need "|" to be "\n"
}

return ReturnVal

See this post for quick exporting to CSV/TSV. It also deals with the codepage problem you will be having.

https://www.ibm.com/developerworks/forums/thread.jspa?threadID=373788&tstart=0

Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS